<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 保证文件名唯一 -->
    <script>
      var getFolderNames = function (names) {
        //使用map方法存放k值
        let arrMap = new Map()
        names.map((item, index) => {
          //如果值存在，则需要添加（k
          if (arrMap[item] != undefined) {
            let flag = true
            while (flag) {
              arrMap[item]++
              names[index] = item + `(${arrMap[item]})`
              //这里需要确保没有存在map中，确保文件名的唯一性
              if (arrMap[names[index]] == undefined) {
                arrMap[names[index]] = 0
                flag = false
              }
            }
          }
          //如果值不纯在，直接将值存入map中，k值为0
          else {
            arrMap[item] = 0
          }
        })
        return names
      }
      console.log(getFolderNames(['pes', 'fifa', 'gta', 'pes(2019)']))
    </script>
  </body>
</html>
